package com.qsbc.pygram.controller;


import com.qsbc.pygram.common.Constants;
import com.qsbc.pygram.common.Result;
import com.qsbc.pygram.entity.Checkpoint;
import com.qsbc.pygram.entity.JudgeQuestion;
import com.qsbc.pygram.entity.MultiQuestion;
import com.qsbc.pygram.entity.PaperManage;
import com.qsbc.pygram.service.JudgeQuestionService;
import com.qsbc.pygram.service.MultiQuestionService;
import com.qsbc.pygram.service.PaperManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2023-01-02
 */
@RestController
@RequestMapping("/pygram/paper-manage")
public class PaperManageController {

    @Autowired
    private PaperManageService paperManageService;

    @Autowired
    private JudgeQuestionService judgeQuestionService;

    @Autowired
    private MultiQuestionService multiQuestionService;


    @GetMapping("/papers")
    public List<PaperManage> findAll() {return paperManageService.findAll();}


    @GetMapping("/paper/{paperId}")
    public Map<Integer, List<?>> findById(@PathVariable("paperId") Integer paperId) {
        List<MultiQuestion> multiQuestionRes = multiQuestionService.findByIdAndType(paperId);   //选择题题库 1
        List<JudgeQuestion> judgeQuestionRes = judgeQuestionService.findByIdAndType(paperId);   //判断题题库 2
        Map<Integer, List<?>> map = new HashMap<>();
        map.put(1,multiQuestionRes);
        map.put(2,judgeQuestionRes);
        return  map;
    }

    @PostMapping("/paperManage")
    public Result add(@RequestBody PaperManage paperManage) {
        int res = paperManageService.add(paperManage);
        if (res != 0) {
            return Result.success().success(res);
        }
        return Result.error().error();
    }

}
